package com.xmb.wechat.dialog;

import android.app.Dialog;
import android.content.Context;
import android.support.annotation.NonNull;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;
import android.widget.TextView;

import com.blankj.utilcode.util.ScreenUtils;
import com.xmb.wechat.R;
import com.xmb.wechat.bean.PYQTrendsBean;
import com.xmb.wechat.definterface.OnDeleteListener;

import java.util.Objects;

/**
 * @Author lijiangop
 * @CreateTime 2020/3/25 16:47
 */
public class DelegateDeleteHintDialog extends Dialog {

    private PYQTrendsBean currentEntity;
    private int           currentPosition;

    public DelegateDeleteHintDialog(@NonNull Context context, String title, OnDeleteListener listener) {
        super(context, R.style.PopupDialog);
        initView(context, title, listener);
    }

    private void initView(Context context, String title, OnDeleteListener listener) {
        View view = LayoutInflater.from(context).inflate(R.layout.dialog_hint, null, false);
        view.findViewById(R.id.tv_cancel).setOnClickListener(v -> {
            dismiss();
        });
        view.findViewById(R.id.tv_confirm).setOnClickListener(v -> {
            if (listener != null)
                listener.onConfirm(currentEntity, currentPosition);
            dismiss();
        });
        TextView tvTitle = view.findViewById(R.id.tv_title);
        if (!TextUtils.isEmpty(title))
            tvTitle.setText(title);
        setContentView(view);
        WindowManager.LayoutParams lp = Objects.requireNonNull(getWindow()).getAttributes();
        lp.width = ScreenUtils.getScreenWidth() / 3 * 2;
        lp.dimAmount = 0.3f;
        getWindow().setAttributes(lp);
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
    }

    public void setData(PYQTrendsBean e, int i) {
        currentEntity = e;
        currentPosition = i;
    }
}
